<html><head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Protected</title></head>
<body bgcolor="#FFFFDF" link="#009999" vlink="#006666" alink="#006666">
<font face="Arial" size="2"><p align="center"><b><font size="5">Protected</font></b></p>

<br><b>Syntax</b><blockquote><pre><font face="Courier New, Courier, mono"size="2"><b><font color="#006666">Protected</font></b>[.&lt;type&gt;] &lt;variable[.&lt;type&gt;]&gt; [= &lt;expression&gt;] [, ...]
</font></pre></blockquote>
<b>Description</b><br><blockquote>


<b><font color="#006666">Protected</font></b> allows a <a href="../reference/variables.html">variable</a> to be accessed only in a <a href="../reference/procedures.html">Procedure</a> even if the same 
variable has been declared as <a href="../reference/global.html">Global</a> in the main program. <b><font color="#006666">Protected</font></b> in its function 
is often known as 'Local' from other BASIC dialects. Each variable can have a default value directly assigned to it. 
If a type is specified after <b><font color="#006666">Protected</font></b>, the default type is changed for this declaration. 
<b><font color="#006666">Protected</font></b> can also be used with <a href="../reference/dim.html">arrays</a>, <a href="../reference/newlist.html">lists</a> and <a href="../reference/newmap.html">maps</a>. <br>
<br>
The value of the local variable will be reinitialized at each procedure call. 
To avoid this, you can use the keyword <a href="../reference/static.html">Static</a>, to separate global from local 
variables while keeping their values. 

 

</blockquote><p><b>Example:</b> With variable</p><blockquote>


<pre><font face="Courier New, Courier, mono"size="2">  <b><font color="#006666">Global</font></b> a
  a = 10
  
  <b><font color="#006666">Procedure</font></b> <font color="#006666">Change</font>()
    <b><font color="#006666">Protected</font></b> a
    a = 20 
  <b><font color="#006666">EndProcedure</font></b> 
  
<font color="#006666">  Change</font>()
  <b><font color="#006666">Debug</font></b> a <font color="#006666">; Will print 10, as the variable has been protected.</font>
</font></pre>

<br>
</blockquote><p><b>Example:</b> With array</p><blockquote>


<pre><font face="Courier New, Courier, mono"size="2">  <b><font color="#006666">Global</font></b> <b><font color="#006666">Dim</font></b> <b><font color="#006666">Array</font></b>(2)
  <b><font color="#006666">Array</font></b>(0) = 10
  
  <b><font color="#006666">Procedure</font></b> <font color="#006666">Change</font>()
    <b><font color="#006666">Protected</font></b> <b><font color="#006666">Dim</font></b> <b><font color="#006666">Array</font></b>(2) <font color="#006666">; This array is protected, it will be local.</font>
    <b><font color="#006666">Array</font></b>(0) = 20 
  <b><font color="#006666">EndProcedure</font></b> 
  
<font color="#006666">  Change</font>()
  <b><font color="#006666">Debug</font></b> <b><font color="#006666">Array</font></b>(0) <font color="#006666">; Will print 10, as the array has been protected.</font>
</font></pre>
</body></html>